const { constants } = require('buffer');
var fs = require('fs');
var path = require('path');

function del(filePath) {
    if (fs.accessSync(filePath,fs.constants.F_OK) == undefined) {
        var fileOrDir = fs.statSync(filePath);
        if (fileOrDir.isDirectory()) {
            var files = fs.readdirSync(filePath);
            files.forEach(element => {
                var childPath = path.join(filePath,"/"+element);
                var fileObj = fs.statSync(childPath);
                if (fileObj.isFile()) {
                    fs.unlinkSync(childPath);
                }
                if (fileObj.isDirectory()) {
                    del(childPath);
                }
            });
            fs.rmdirSync(filePath);
        }
        if (fileOrDir.isFile()) {
            // console.log("执行了该分支")
            fs.unlinkSync(filePath)
        }
    }
    else{
        console.log("路径不存在！！！")
    }
}
module.exports = del;